package org.dromara.app.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.app.domain.vo.SkYueJuDemoVo;
import org.dromara.app.domain.bo.SkYueJuDemoBo;
import org.dromara.app.service.ISkYueJuDemoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 约局模版
 *
 * @author Evacuation
 * @date 2024-07-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/SkYueJuDemo")
public class SkYueJuDemoController extends BaseController {

    private final ISkYueJuDemoService skYueJuDemoService;

    /**
     * 查询约局模版列表
     */
    @SaCheckPermission("app:SkYueJuDemo:list")
    @GetMapping("/list")
    public TableDataInfo<SkYueJuDemoVo> list(SkYueJuDemoBo bo, PageQuery pageQuery) {
        return skYueJuDemoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出约局模版列表
     */
    @SaCheckPermission("app:SkYueJuDemo:export")
    @Log(title = "约局模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SkYueJuDemoBo bo, HttpServletResponse response) {
        List<SkYueJuDemoVo> list = skYueJuDemoService.queryList(bo);
        ExcelUtil.exportExcel(list, "约局模版", SkYueJuDemoVo.class, response);
    }

    /**
     * 获取约局模版详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("app:SkYueJuDemo:query")
    @GetMapping("/{id}")
    public R<SkYueJuDemoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(skYueJuDemoService.queryById(id));
    }

    /**
     * 新增约局模版
     */
    @SaCheckPermission("app:SkYueJuDemo:add")
    @Log(title = "约局模版", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SkYueJuDemoBo bo) {
        return toAjax(skYueJuDemoService.insertByBo(bo));
    }

    /**
     * 修改约局模版
     */
    @SaCheckPermission("app:SkYueJuDemo:edit")
    @Log(title = "约局模版", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SkYueJuDemoBo bo) {
        return toAjax(skYueJuDemoService.updateByBo(bo));
    }

    /**
     * 删除约局模版
     *
     * @param ids 主键串
     */
    @SaCheckPermission("app:SkYueJuDemo:remove")
    @Log(title = "约局模版", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(skYueJuDemoService.deleteWithValidByIds(List.of(ids), true));
    }
}
